package system

import chisel3._
import top.Settings

object AddrSpace {

  // // CLINT
  // val addrSpace = List(
  //     (Settings.getLong("MMIOBase"), Settings.getLong("MMIOSize")), // external devices
  //     //(0x38000000L, 0x00010000L),
  //     (0x2000000L, 0x00010000L), // CLINT
  //     //(0x3c000000L, 0x04000000L)  // PLIC
  // )
  def mmioAddrSpace = List(
    (Settings.getLong("MMIOBase"), Settings.getLong("MMIOSize")), // external devices
    (0x2000000L, 0x00010000L), // CLINT
    //(0x3c000000L, 0x04000000L)  // PLIC
  )

  def isMMIO(addr: UInt) = {
    val selVec = VecInit(mmioAddrSpace.map(range => (addr >= range._1.U && addr < (range._1 + range._2).U)))
    val hit = selVec.asUInt().orR()
    hit
  }
}
